package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.BGreenCarbonSink;
import com.isdepci.project.carbon.domain.BGreenCarbonSinkParameter;
import com.isdepci.project.carbon.domain.param.WeatherDataExcel;
import com.isdepci.project.carbon.service.IBGreenCarbonSinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 绿化碳汇Controller
 *
 * @author isdepci
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/greenCarbon/sink")
public class BGreenCarbonSinkController extends BaseController
{
    @Autowired
    private IBGreenCarbonSinkService bGreenCarbonSinkService;


    /**
     * 查询绿化类型查询参数
     */
    @GetMapping("/getGreenCarbonSinkParameters")
    public BGreenCarbonSinkParameter getGreenCarbonSinkParameters(@RequestParam Integer greeningType) {
        return bGreenCarbonSinkService.getGreenCarbonSinkParameters(greeningType);
    }

    /**
     * 绿化碳汇计算
     */
    @GetMapping("/calGreenCarbon")
    public AjaxResult calGreenCarbon(@RequestParam Long projectId) {
        return bGreenCarbonSinkService.calGreenCarbon(projectId);
    }



    /**
     * 查询绿化碳汇列表
     */
    //   @PreAuthorize("@ss.hasPermi('greenCarbon:sink:list')")
    @GetMapping("/list")
    public TableDataInfo list(BGreenCarbonSink bGreenCarbonSink)
    {
        startPage();
        List<BGreenCarbonSink> list = bGreenCarbonSinkService.selectBGreenCarbonSinkList(bGreenCarbonSink);
        return getDataTable(list);
    }

    /**
     * 导出绿化碳汇列表
     */
    //   @PreAuthorize("@ss.hasPermi('greenCarbon:sink:export')")
    @Log(title = "绿化碳汇", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BGreenCarbonSink bGreenCarbonSink)
    {
        List<BGreenCarbonSink> list = bGreenCarbonSinkService.selectBGreenCarbonSinkList(bGreenCarbonSink);
        ExcelUtil<BGreenCarbonSink> util = new ExcelUtil<BGreenCarbonSink>(BGreenCarbonSink.class);
        return util.exportExcel(list, "sink");
    }

    /**
     * 上传保存数据
     * @param excel
     * @return
     */
    @PostMapping("/changeData")
    public AjaxResult changeDataByProjectId(@RequestBody WeatherDataExcel excel) {
        return bGreenCarbonSinkService.changeDataByProjectId(excel);
    }



    /**
     * 获取绿化碳汇详细信息
     */
    //   @PreAuthorize("@ss.hasPermi('greenCarbon:sink:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bGreenCarbonSinkService.selectBGreenCarbonSinkById(id));
    }

    /**
     * 新增绿化碳汇
     */
    //   @PreAuthorize("@ss.hasPermi('greenCarbon:sink:add')")
    @Log(title = "绿化碳汇", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BGreenCarbonSink bGreenCarbonSink)
    {
        return toAjax(bGreenCarbonSinkService.insertBGreenCarbonSink(bGreenCarbonSink));
    }

    /**
     * 修改绿化碳汇
     */
    //   @PreAuthorize("@ss.hasPermi('greenCarbon:sink:edit')")
    @Log(title = "绿化碳汇", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BGreenCarbonSink bGreenCarbonSink)
    {
        return toAjax(bGreenCarbonSinkService.updateBGreenCarbonSink(bGreenCarbonSink));
    }

    /**
     * 删除绿化碳汇
     */
    //   @PreAuthorize("@ss.hasPermi('greenCarbon:sink:remove')")
    @Log(title = "绿化碳汇", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bGreenCarbonSinkService.deleteBGreenCarbonSinkByIds(ids));
    }
}
